package com.swn.common.util;

import org.springframework.context.support.ClassPathXmlApplicationContext;

public class SpringContext
{
    private static ClassPathXmlApplicationContext context = null;

    /**
     * 从spring的工厂读取bean
     */
    public static Object getBean(String beanName)
    {
        checkContext();
        return context.getBean(beanName);
    }

    /**
     * 初始化spring应用上下文
     */
    private synchronized static void checkContext()
    {
    	if (context == null) {
            context = new ClassPathXmlApplicationContext("classpath:spring.xml");
        }
    }

	public static ClassPathXmlApplicationContext getContext() {
		checkContext();
		return context;
	}

	public static void setContext(ClassPathXmlApplicationContext context) {
		SpringContext.context = context;
	}


}

	
    
    
